﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;

namespace UnityEngine.Graphics.Texture.Ijl15
{
    class NativeMethods
    {
        [DllImport("ijl15.dll", EntryPoint = "ijlInit", CallingConvention = CallingConvention.StdCall)]
        public static extern IJLERR ijlInit(ref JPEG_CORE_PROPERTIES jcprops);


        [DllImport("ijl15.dll", EntryPoint = "ijlFree", CallingConvention = CallingConvention.StdCall)]
        public static extern IJLERR ijlFree(ref JPEG_CORE_PROPERTIES jcprops);

        [DllImport("ijl15.dll", EntryPoint = "ijlRead", CallingConvention = CallingConvention.StdCall)]
        public static extern IJLERR ijlRead(ref JPEG_CORE_PROPERTIES jcprops, IJLIOTYPE iotype);

        [DllImport("ijl15.dll", EntryPoint = "ijlErrorStr", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)]
        public static extern string ijlErrorStr(IJLERR code);

        #region c++ marco
        public static int IJL_DIB_UWIDTH(int width, int nchannels)
        {
            return width * nchannels;
        }

        static int IJL_DIB_ALIGN = sizeof(int) - 1;

        public static int IJL_DIB_AWIDTH(int width, int nchannels)
        {
            return ((IJL_DIB_UWIDTH(width, nchannels) + IJL_DIB_ALIGN) & (~IJL_DIB_ALIGN));
        }

        public static int IJL_DIB_PAD_BYTES(int width, int nchannels)
        {
            return (IJL_DIB_AWIDTH(width, nchannels) - IJL_DIB_UWIDTH(width, nchannels));
        }

        public static int IJL_DIB_SCALE_SIZE(int jpgsize, int scale)
        {
            return (((jpgsize) + (scale) - 1) / (scale));
        }

        public static uint BI_RGB = 0;
        #endregion
    }
}
